package cn.com.qiancheng.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.com.qiancheng.dto.Evaluation;
import cn.com.qiancheng.dto.TrinerClass;
import cn.com.qiancheng.util.DbUtil;

public class EvaluationDao {
	public Evaluation sreachEvaluation(int id) {
		Evaluation eva = null;
		try {
			Connection con = DbUtil.openConnection();
			String sql = "SELECT " + "eva_id," + "eva_name," + "eva_class_id," + "eva_exam_id," + "eva_tea_id,"
					+ "eva_date " + "FROM t_evaluation WHERE eva_id =?";
			PreparedStatement stat = con.prepareStatement(sql);
			stat.setInt(1, id);
			ResultSet rs = stat.executeQuery();
			while (rs.next()) {
				eva = new Evaluation();
				eva.setEvaId(rs.getInt("eva_id"));
				eva.setDate(rs.getString("eva_date"));
				eva.setEvaName(rs.getString("eva_name"));
				eva.setExamPaper(new ExamPaperDao().searchExamPaper(rs.getInt("eva_exam_id")));
				eva.setTeacher(new TeacherDao().sreachEvaluation(rs.getInt("eva_tea_id")));
				eva.settClass(new TrinerClassDao().sreachTrinerClass(rs.getInt("eva_class_id")));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				DbUtil.closeConnection();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return eva;
	}
}
